<?php
    /**
     * Created by PhpStorm.
     * User: huangzhongwei
     * Date: 2018/10/24
     * Time: 14:40
     */

    namespace app\common\model;


    use think\Model;

    class HarvestAddress extends Model
    {
        protected $table = "harvest_address";
        protected $autoWriteTimestamp = true;

        public static function getAddressByUniversityId($uid,$type,$university_id)
        {

            $result = self::where(['account_id'=>$uid,'type'=>$type,'university_id'=>$university_id])->with('university')->select();
            return $result;
        }

        public static function getDefaultAddress( $uid,$university_id,$type)
        {
            $defaultAddress = self::where(['account_id' => $uid,'type'=>$type, 'university_id' => $university_id, 'default_address' => 1])
                                                 ->find();
            return $defaultAddress;
        }

        public function university()
        {
            return $this->belongsTo('university', 'university_id');
        }

    }